// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi
// Source File Name:   CMPPMessage.java

package com.haoxi.gateway.test.message;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

import com.haoxi.gateway.test.PMessage;
import com.haoxi.gateway.test.util.TypeConvert;

public abstract class CMPPMessage extends PMessage implements Cloneable {
    private static int i = 1;
    protected int nSequenceID = 0;
    protected byte buf[];
    protected final Object syn_index_obj = new Object();
    protected static int ENDNUM = 99;
    protected static int CURRENTNUM = 0;
    protected static int STARTNUM = 0;
    protected int src_node_Id;
    protected int time_Stamp;
    protected int sequence_Id;
    protected int message_Length;
    protected int command_ID;

    protected byte[] getMsgID1() {
        SimpleDateFormat format = new SimpleDateFormat("ms");
        byte[] result = new byte[8];
        String data = format.format(new Date());
        int ms = Integer.parseInt(data.substring(0, 2));
        result[0] = (byte) ms;
        Random ran = new Random();
        byte[] b = new byte[3];
        ran.nextBytes(b);
        System.arraycopy(b, 0, result, 1, 3);
        TypeConvert.int2byte(sequence_Id, result, 4);
        // log.info("msgid:"+result[0]+result[1]+result[2]+result[3]+result[4]+result[5]+result[6]+result[7]);
        return result;
    }

    public CMPPMessage() {
    }

    public Object clone() {
        try {
            CMPPMessage m = (CMPPMessage) super.clone();
            m.buf = (byte[]) buf.clone();
            CMPPMessage cmppmessage = m;
            return cmppmessage;
        } catch (CloneNotSupportedException ex) {
            ex.printStackTrace();
        }
        Object obj = null;
        return obj;
    }

    public abstract String toString();

    public abstract int getCommandId();

    public int getSequenceId() {
        return sequence_Id;
    }

    public void setSequenceID() {
        nSequenceID = i;
        i++;
        if (i == 0x7fffffff) {
            i = 1;
        }
        setSequenceId(i);
    }

    public int getMessage_Length() {
        return message_Length;
    }

    public void setSequenceId(int sequence_Id) {
        this.sequence_Id = sequence_Id;
        TypeConvert.int2byte(sequence_Id, buf, 8);
    }

    public byte[] getBytes() {
        return buf;
    }
}
